package com.docus.bgts.handler;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.encoding.XMLType;

import java.net.MalformedURLException;
import java.rmi.RemoteException;

public class TestMain {

    public static void main(String[] args) throws MalformedURLException, ServiceException, RemoteException {
//        TBasicWebServiceService serviceService=new TBasicWebServiceService();
//        TBasicWebService service = serviceService.getTBasicWebServicePort();
        // 1、创建document对象
        Document document = DocumentHelper.createDocument();
        // 2、创建根节点rss
        Element Requst = document.addElement("Requst");
        Element msg = Requst.addElement("Msg");
        Element testItemInfo = msg.addElement("PatInfo");
//        Element testItemInfo = patInfo1.addElement("TestItemInfo");
        testItemInfo.addElement("jzh").setText("5555566666");
        testItemInfo.addElement("PATHOLOGY_ONLY_NO").setText("1898989");
        testItemInfo.addElement("EXAM_ITEM_NAME").setText("15689文件");
        testItemInfo.addElement("IMAGE_URL").setText("http://192.168.1.107:9000/image/systemLogo.png");
//        Element patInfo = patInfo1.addElement("TestItemInfo");
//        patInfo.addElement("jzh").setText("asdkjqwe");
//        patInfo.addElement("PATHOLOGY_ONLY_NO").setText("51231l");
//        patInfo.addElement("EXAM_ITEM_NAME").setText("文举报他wej6");
//        patInfo.addElement("IMAGE_URL").setText("http://www.aqweqwe.cn");
        // 5、设置生成xml的格式
        OutputFormat format = OutputFormat.createPrettyPrint();
        // 设置编码格式
        format.setEncoding("UTF-8");
        String xml = document.asXML();

        String requestUrl = "http://127.0.0.1:9202/201_P_WS_JYBGTS?wsdl";
        String requestXml = xml;
        Object[] object = new Object[] { requestXml };//请求参数
        Service service = new Service();
        Call call = (Call) service.createCall();
        call.setTargetEndpointAddress(requestUrl);// 远程调用路径
        // 调用的命名空间和方法名
        call.setOperationName(new QName("http://handler.bgts.docus.com/", "pushSurveyReport"));
        call.setUseSOAPAction(true);
        //可以在wsdl中找个这个地址
        call.setSOAPActionURI("http://handler.bgts.docus.com/pushSurveyReport");
//        call.addParameter("string",XMLType.XSD_INT,javax.xml.rpc.ParameterMode.IN);
        //命名空间和参数名，参数名不可以随便写,参数名可以在wsdl文件中找到
//        call.addParameter(new QName("http://handler.bgts.docus.com/","pushSurveyReport"),
//               XMLType.XSD_STRING, ParameterMode.IN);
        call.addParameter("arg0", XMLType.XSD_STRING,ParameterMode.IN);
        call.setReturnType(XMLType.XSD_STRING);// 返回值类型：String
        call.setTimeout(100000);//超时
        String result = (String) call.invoke(object);// 远程调用
        System.out.println(result);

//        String bipEndpoint = "http://127.0.0.1:9203/204_P_WS_BLBGTS?wsdl";
//        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
//        org.apache.cxf.endpoint.Client client = dcf.createClient(bipEndpoint);
//        Object[] objects;
//        String result = "";
//        try {
//            //命名空间:http://lfieng.com/  ,getName:方法,1829571****:方法的入参
//            objects = client.invoke(new QName("http://handler.bgts.docus.com/", "pushSurveyReport"), xml);
//            result = objects[0].toString();// 远程调用
//            // 输出调用结果
//            System.out.println("接口服务返回数据：\n" + result);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//        URL url = new URL("http://127.0.0.1:9203/204_P_WS_BLBGTS?wsdl");
//        QName qName = new QName("http://handler.bgts.docus.com/", "TBasicWebServiceService");
//        Service service = Service.create(url, qName);
//        // 通过getPort方法返回指定接口
//        MyService myServer = service.getPort(new QName("http://handler.bgts.docus.com/",
//                "TBasicWebServicePort"), MyService.class);
//        // 调用方法 获取返回值
//        String result = myServer.pushSurveyReport(xml);
//        System.out.println(result);
//        String res = service.pushSurveyReport(xml);
//        System.out.println(res);
    }
}




